import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestJ:
    def setup_method(self):
        self.driver=webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('https://www.jiuxian.com/')

    def teardown_method(self):
        time.sleep(2)
        self.driver.quit()

    def test_jiuxianw_001_login(self):
        # 点击请登录
        self.driver.find_element(By.CSS_SELECTOR, '.headerLogin').click()
        # 断言1  断言文本：账号登录
        dy1 = self.driver.find_element(By.XPATH, '//a[@href="javascript:;"]').text
        print(dy1)
        time.sleep(8)
        # 用户名
        self.driver.find_element(By.ID, 'userName').send_keys("13103053968")
        # 密码
        self.driver.find_element(By.NAME, '_pwd').send_keys("jiuxianwang123aaa")
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.NAME, 'bi_Usuallogin').click()
        time.sleep(8)
        # 登录成功 跳转到首页 断言文本 断言jxw862549358
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
        print(dy2)
        time.sleep(8)

    def test_jiuxianw_002_search(self):
        self.test_jiuxianw_001_login()
        # 点击首页
        self.driver.find_element(By.ID, 'httpwwwjiuxiancom').click()
        # 首页输入框定位
        self.driver.find_element(By.NAME, 'key').send_keys("雪花")
        # 点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, '.search-btn').click()
        # 断言 断言文本 断言雪花
        self.driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/div[1]/div[2]/a[2]').click()
        time.sleep(5)
        # 点击雪花啤酒图片  第一个图片
        self.driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img').click()
        time.sleep(10)